package com.atguigu.tingshu.payment.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.payment.service.WxPayService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment")
@Slf4j
public class WxPayApiController {

    @Autowired
    private WxPayService wxPayService;


    /**
     * 支付状态查询（同步查询）
     * /api/payment/wxPay/queryPayStatus/{orderNo}
     * @param orderNo
     * @return
     */
    @GetMapping("/wxPay/queryPayStatus/{orderNo}")
    public Result<Boolean> queryPayStatus(@PathVariable String orderNo) {
        Boolean flag = wxPayService.queryPayStatus(orderNo);
        return Result.ok(flag);
    }


    /**
     * 微信下单
     * /api/payment/wxPay/createJsapi/{paymentType}/{orderNo}
     * @param paymentType
     * @param orderNo
     * @return
     */
    @PostMapping("/wxPay/createJsapi/{paymentType}/{orderNo}")
    @GuiGuLogin
    public Result<Map<String, Object>> createJsapi(@PathVariable String paymentType,
                                                   @PathVariable String orderNo) {
        log.info("开始创建微信支付订单");
        Map<String, Object> map = wxPayService.createJsapi(paymentType, orderNo);
        return Result.ok(map);
    }

}
